package org.learn.intermediate.homework01;

import java.io.*;

public class HomeWork04 {
    public static void main(String[] args) throws IOException {
        String directoryPath = "d:\\mytemp";
        File file = new File(directoryPath);
        if (!file.exists()) {
            //创建
            if (file.mkdirs()) {
                System.out.println("创建" + directoryPath + "创建成功");


            } else {
                System.out.println("创建" + directoryPath + "创建失败");
            }
        }
        String filePath = directoryPath + "\\hello.txt";
        file = new File(filePath);
        //创建文件
        if (file.createNewFile()) {
            System.out.println(filePath + "创建成功");

            //如果文件存在，我们就使用BufferedWriter 字符输入流写入内容
            BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file));
            bufferedWriter.write("hello,world");
            bufferedWriter.close();

        } else {
            System.out.println(filePath + "创建失败");
        }
    }
}
